<div class="content-section introduction">
    <div class="feature-intro">
        <h1>OrganizationChart</h1>
        <p>OrganizationChart visualizes hierarchical organization data.</p>
    </div>
</div>

<div class="content-section implementation">
    <p-toast></p-toast>

    <div class="card">
        <h5>Advanced</h5>
        <p-organizationChart [value]="data1" selectionMode="single" [(selection)]="selectedNode" (onNodeSelect)="onNodeSelect($event)"
            styleClass="company">
            <ng-template let-node pTemplate="person">
                <div class="node-header p-corner-top">{{node.label}}</div>
                <div class="node-content">
                    <img src="assets/showcase/images/demo/organization/{{node.data.avatar}}" width="32">
                    <div>{{node.data.name}}</div>
                </div>
            </ng-template>
            <ng-template let-node pTemplate="department">
                {{node.label}}
            </ng-template>
        </p-organizationChart>
    </div>

    <div class="card">
        <h5>Basic</h5>
        <p>Hierarchical data with zero configuration.</p>
        <p-organizationChart [value]="data2"></p-organizationChart>
    </div>
</div>

<div class="content-section documentation">
    <p-tabView>
        <p-tabPanel header ="Documentation">
            <h5>Import</h5>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;OrganizationChartModule&#125; from 'primeng/organizationchart';
</app-code>

            <h5>Getting Started</h5>
            <p>OrganizationChart requires a model of TreeNode as its <i>value</i>. More information about TreeNode API is available at documentation of <a href="#" [routerLink]="['/tree']">tree</a> component.</p>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;TreeNode&#125; from 'primeng/api';
</app-code>


<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-organizationChart [value]="data"&gt;&lt;/p-organizationChart&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class MyComponents implements OnInit &#123;

    data: TreeNode[];

    ngOnInit() &#123;
        this.data = [&#123;
            label: 'Root',
            children: [
                &#123;
                    label: 'Child 1',
                    children: [
                        &#123;
                            label: 'Grandchild 1.1'
                        &#125;,
                        &#123;
                            label: 'Grandchild 1.2'
                        &#125;
                    ]
                &#125;,
                &#123;
                    label: 'Child 2',
                    children: [
                        &#123;
                            label: 'Child 2.1'
                        &#125;,
                        &#123;
                            label: 'Child 2.2'
                        &#125;
                    ]
                &#125;
            ]
        &#125;];
&#125;
</app-code>

            <h5>Templating</h5>
            <p>Label of the treenode is displayed inside the node content by default and templating enables enhanced customization. TreeNode API has type property which is
            used to match the <i>pTemplate</i> type so templating can be done per node as well. In example below, nodes with type "leaf" are displayed with bold text. Note that a pTemplate
            whose type is "default" applies to all nodes that have no type property defined.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-organizationChart [value]="data"
    styleClass="company"&gt;
    &lt;ng-template let-node pTemplate="leaf"&gt;
        &lt;span style="font-weight:bold"&gt;{{node.label}}&lt;/span&gt;
    &lt;/ng-template&gt;
    &lt;ng-template let-node pTemplate="default"&gt;
        &#123;&#123;node.label&#125;&#125;
    &lt;/ng-template&gt;
&lt;/p-organizationChart&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class MyComponents implements OnInit &#123;

    data: TreeNode[];

    ngOnInit() &#123;
        this.data = [&#123;
            label: 'Root',
            children: [
                &#123;
                    label: 'Child 1',
                    children: [
                        &#123;
                            label: 'Grandchild 1.1', type: 'leaf'
                        &#125;,
                        &#123;
                            label: 'Grandchild 1.2', type: 'leaf'
                        &#125;
                    ]
                &#125;,
                &#123;
                    label: 'Child 2',
                    children: [
                        &#123;
                            label: 'Child 2.1', type: 'leaf'
                        &#125;,
                        &#123;
                            label: 'Child 2.2', type: 'leaf'
                        &#125;
                    ]
                &#125;
            ]
        &#125;];
&#125;
</app-code>

            <h5>Expand/Collapse State</h5>
            <p>In order to display a treenode as <i>expanded</i> by default, set "expanded" property as true in your model.</p>

            <h5>Selection</h5>
            <p>OrganizationChart supports 2 selection methods; single or multiple. Selection is enabled by setting <i>selectionMode</i> property and providing a single TreeNode or
            an array of TreeNodes to reference the selections depending on the selection mode.</p>

<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-organizationChart [value]="data" selectionMode="single" [(selection)]="selectedNode"&gt;&lt;/p-organizationChart&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class MyComponents implements OnInit &#123;

    data: TreeNode[];

    ngOnInit() &#123;
        this.data = [&#123;
            label: 'Root',
            children: [
                &#123;
                    label: 'Child 1,
                    children: [
                        &#123;
                            label: 'Grandchild 1.1', type: 'leaf'
                        &#125;,
                        &#123;
                            label: 'Grandchild 1.2', type: 'leaf'
                        &#125;
                    ]
                &#125;,
                &#123;
                    label: 'Child 2',
                    children: [
                        &#123;
                            label: 'Child 2.1', type: 'leaf'
                        &#125;,
                        &#123;
                            label: 'Child 2.2', type: 'leaf'
                        &#125;
                    ]
                &#125;
            ]
        &#125;];
&#125;
</app-code>

            <h5>Properties</h5>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Type</th>
                            <th>Default</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>value</td>
                            <td>null</td>
                            <td>TreeNode[]</td>
                            <td>An array of nested TreeNodes.</td>
                        </tr>
                        <tr>
                            <td>style</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Inline style of the component.</td>
                        </tr>
                        <tr>
                            <td>styleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the component.</td>
                        </tr>
                        <tr>
                            <td>selectionMode</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Defines the selection mode, valid values "single" and "multiple".</td>
                        </tr>
                        <tr>
                            <td>selection</td>
                            <td>any</td>
                            <td>null</td>
                            <td>A single treenode instance or an array to refer to the selections.</td>
                        </tr>
                        <tr>
                            <td>preserveSpace</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Whether the space allocated by a node is preserved when hidden.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

        <h5>Events</h5>
        <div class="doc-tablewrapper">
            <table class="doc-table">
                <thead>
                <tr>
                    <th>Name</th>
                    <th>Parameters</th>
                    <th>Description</th>
                </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>onNodeSelect</td>
                        <td>event.originalEvent: browser event <br>
                            event.node: Selected node instance.</td>
                        <td>Callback to invoke when a node is selected.</td>
                    </tr>
                    <tr>
                        <td>onNodeUnselect</td>
                        <td>event.originalEvent: browser event <br>
                            event.node: Unselected node instance.</td>
                        <td>Callback to invoke when a node is unselected.</td>
                    </tr>
                    <tr>
                        <td>onNodeExpand</td>
                        <td>event.originalEvent: browser event <br>
                            event.node: Expanded node instance.</td>
                        <td>Callback to invoke when a node is expanded.</td>
                    </tr>
                    <tr>
                        <td>onNodeCollapse</td>
                        <td>event.originalEvent: browser event <br>
                            event.node: Collapsed node instance.</td>
                        <td>Callback to invoke when a node is collapsed.</td>
                    </tr>
                </tbody>
            </table>
        </div>

        <h5>Styling</h5>
        <p>Following is the list of structural style classes, for theming classes visit <a href="#" [routerLink]="['/theming']">theming page</a>.</p>
        <div class="doc-tablewrapper">
            <table class="doc-table">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Element</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>p-organizationchart</td>
                        <td>Container element.</td>
                    </tr>
                    <tr>
                        <td>p-organizationchart-table</td>
                        <td>Table container of a node.</td>
                    </tr>
                    <tr>
                        <td>p-organizationchart-lines</td>
                        <td>Connector lines container.</td>
                    </tr>
                    <tr>
                        <td>p-organizationchart-nodes</td>
                        <td>Contained of node children.</td>
                    </tr>
                    <tr>
                        <td>p-organizationchart-line-right</td>
                        <td>Right side line of a node connector.</td>
                    </tr>
                    <tr>
                        <td>p-organizationchart-line-left</td>
                        <td>Left side line of a node connector.</td>
                    </tr>
                    <tr>
                        <td>p-organizationchart-line-top</td>
                        <td>Top side line of a node connector.</td>
                    </tr>
                </tbody>
            </table>
        </div>

        <h5>Dependencies</h5>
        <p>None.</p>

        </p-tabPanel>

        <p-tabPanel header="Source">
            <a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/organizationchart" class="btn-viewsource" target="_blank">
                <span>View on GitHub</span>
            </a>
            <a href="https://stackblitz.com/edit/primeng-organizationchart-demo" class="btn-viewsource" style="margin-left: .5em;" target="_blank">
                <span>Edit in StackBlitz</span>
            </a>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-toast [style]="&#123;marginTop: '80px'&#125;"&gt;&lt;/p-toast&gt;

&lt;h5&gt;Advanced&lt;/h5&gt;
&lt;p&gt;Organization with advanced customization.&lt;/p&gt;
&lt;p-organizationChart [value]="data1" selectionMode="single" [(selection)]="selectedNode" (onNodeSelect)="onNodeSelect($event)"
    styleClass="company"&gt;
    &lt;ng-template let-node pTemplate="person"&gt;
        &lt;div class="node-header p-corner-top"&gt;&#123;node.label&#125;&lt;/div&gt;
        &lt;div class="node-content"&gt;
            &lt;img src="assets/showcase/images/demo/organization/&#123;node.data.avatar&#125;" width="32"&gt;
            &lt;div&gt;&#123;node.data.name&#125;&lt;/div&gt;
        &lt;/div&gt;
    &lt;/ng-template&gt;
    &lt;ng-template let-node pTemplate="department"&gt;
        &#123;node.label&#125;
    &lt;/ng-template&gt;
&lt;/p-organizationChart&gt;

&lt;h5&gt;Basic&lt;/h5&gt;
&lt;p&gt;Hierarchical data with zero configuration.&lt;/p&gt;
&lt;p-organizationChart [value]="data2"&gt;&lt;/p-organizationChart&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class OrganizationChartDemo implements OnInit &#123;

    data1: TreeNode[];

    data2: TreeNode[];

    selectedNode: TreeNode;

    constructor(private messageService: MessageService) &#123;&#125;

    ngOnInit() &#123;
        this.data1 = [&#123;
            label: 'CEO',
            type: 'person',
            styleClass: 'p-person',
            expanded: true,
            data: &#123;name:'Walter White', 'avatar': 'walter.jpg'&#125;,
            children: [
                &#123;
                    label: 'CFO',
                    type: 'person',
                    styleClass: 'p-person',
                    expanded: true,
                    data: &#123;name:'Saul Goodman', 'avatar': 'saul.jpg'&#125;,
                    children:[&#123;
                        label: 'Tax',
                        styleClass: 'department-cfo'
                    &#125;,
                    &#123;
                        label: 'Legal',
                        styleClass: 'department-cfo'
                    &#125;],
                &#125;,
                &#123;
                    label: 'COO',
                    type: 'person',
                    styleClass: 'p-person',
                    expanded: true,
                    data: &#123;name:'Mike E.', 'avatar': 'mike.jpg'&#125;,
                    children:[&#123;
                        label: 'Operations',
                        styleClass: 'department-coo'
                    &#125;]
                &#125;,
                &#123;
                    label: 'CTO',
                    type: 'person',
                    styleClass: 'p-person',
                    expanded: true,
                    data: &#123;name:'Jesse Pinkman', 'avatar': 'jesse.jpg'&#125;,
                    children:[&#123;
                        label: 'Development',
                        styleClass: 'department-cto',
                        expanded: true,
                        children:[&#123;
                            label: 'Analysis',
                            styleClass: 'department-cto'
                        &#125;,
                        &#123;
                            label: 'Front End',
                            styleClass: 'department-cto'
                        &#125;,
                        &#123;
                            label: 'Back End',
                            styleClass: 'department-cto'
                        &#125;]
                    &#125;,
                    &#123;
                        label: 'QA',
                        styleClass: 'department-cto'
                    &#125;,
                    &#123;
                        label: 'R&amp;D',
                        styleClass: 'department-cto'
                    &#125;]
                &#125;
            ]
        &#125;];

        this.data2 = [&#123;
            label: 'F.C Barcelona',
            expanded: true,
            children: [
                &#123;
                    label: 'F.C Barcelona',
                    expanded: true,
                    children: [
                        &#123;
                            label: 'Chelsea FC'
                        &#125;,
                        &#123;
                            label: 'F.C. Barcelona'
                        &#125;
                    ]
                &#125;,
                &#123;
                    label: 'Real Madrid',
                    expanded: true,
                    children: [
                        &#123;
                            label: 'Bayern Munich'
                        &#125;,
                        &#123;
                            label: 'Real Madrid'
                        &#125;
                    ]
                &#125;
            ]
        &#125;];
    &#125;

    onNodeSelect(event) &#123;
        this.messageService.add(&#123;severity: 'success', summary: 'Node Selected', detail: event.node.label&#125;);
    &#125;
&#125;
</app-code>

<app-code lang="css" ngNonBindable ngPreserveWhitespaces>
:host ::ng-deep .p-organizationchart &#123;
    .p-person &#123;
        padding: 0;
        border: 0 none;
    &#125;

    .node-header, .node-content &#123;
        padding: .5em .7rem;
    &#125;

    .node-header &#123;
        background-color: #495ebb;
        color: #ffffff;
    &#125;

    .node-content &#123;
        text-align: center;
        border: 1px solid #495ebb;
    &#125;

    .node-content img &#123;
        border-radius: 50%;
    &#125;

    .department-cfo &#123;
        background-color: #7247bc;
        color: #ffffff;
    &#125;

    .department-coo &#123;
        background-color: #a534b6;
        color: #ffffff;
    &#125;

    .department-cto &#123;
        background-color: #e9286f;
        color: #ffffff;
    &#125;
&#125;
</app-code>
        </p-tabPanel>
        <p-tabPanel header="StackBlitz">
            <ng-template pTemplate="content">
                <iframe src="https://stackblitz.com/edit/primeng-organizationchart-demo?embed=1" style="width: 100%; height: 768px; border: none;"></iframe>
            </ng-template>
        </p-tabPanel>
    </p-tabView>
</div>
